//
//  WATFUPResultViewController.swift
//  WiFiFaster
//
//  Created by one on 2023/12/28.
//

import UIKit

class WATFUPResultViewController: WATFResultViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
       
    }
    

    // MARK: - watf action
    override func watf_layout() -> UICollectionViewFlowLayout {
        let watf_layout = UICollectionViewFlowLayout()
        watf_layout.itemSize = CGSize(width: watf_SCREEN_WIDTH-40, height: 84)
        watf_layout.minimumLineSpacing = 16
        return watf_layout
    }
    override func watf_collectionViews() {
        super.watf_collectionViews()
        watf_collectionView.addSubview(watf_titleLabel)
        watf_titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(-64)
        }
        watf_collectionView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(15)
            make.left.width.equalToSuperview()
            make.height.equalTo(395)
            make.bottom.equalToSuperview()
        }
        watf_collectionView.register(WARTFUPResultCell.classForCoder(), forCellWithReuseIdentifier: WARTFUPResultCell.watf_viewToString)
        watf_collectionView.backgroundColor = WATFCommon.watf_getHXColorValue(rgb: 0x322E2B)
        watf_collectionView.layer.cornerRadius = 32
        watf_collectionView.layer.maskedCorners = [ .layerMaxXMinYCorner, .layerMinXMinYCorner]
        watf_collectionView.dataSource = self
        watf_collectionView.delegate = self
        watf_collectionView.contentInset = UIEdgeInsets(top: 84, left: 0, bottom: 0, right: 0)
    }
    // MARK: - watf lazy
    lazy var watf_titleLabel: UILabel = {
        let watf_titleLabel = UILabel()
        watf_titleLabel.textColor = .white
        watf_titleLabel.font = UIFont.boldSystemFont(ofSize: 18)
        watf_titleLabel.text = "The following functions can\nincrease speed"
        watf_titleLabel.textAlignment = .center
        watf_titleLabel.numberOfLines = 2
        return watf_titleLabel
    }()
    var watf_funcModels = WATFManager.watf_manager.watf_funcModels.filter { watf_funcModel in
        return watf_funcModel.watf_type != .watf_speed && watf_funcModel.watf_type != .watf_speedUP
    }
}
 
extension WATFUPResultViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return watf_funcModels.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let watf_cell = collectionView.dequeueReusableCell(withReuseIdentifier: WARTFUPResultCell.watf_viewToString, for: indexPath) as! WARTFUPResultCell
        let watf_funcModel =  watf_funcModels[indexPath.row]
        watf_cell.watf_rowLabel.text = "\(indexPath.row + 1)"
        watf_cell.watf_titleLabel.text = watf_funcModel.watf_title
        watf_cell.watf_stateView.image = UIImage(named: watf_funcModel.watf_complete ? "watf_result_upComplete" : "watf_result_upUnComplete")
        return watf_cell
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let watf_funcModel = watf_funcModels[indexPath.row]
        watf_funcClickModel(watf_funcModel: watf_funcModel)
    }
}
